package org.itboys.seller.service;

import com.google.common.collect.Maps;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseService;
import org.itboys.seller.constant.SellerConstants;
import org.itboys.seller.entity.SellerBank;
import org.itboys.seller.entity.SellerGetMoneyRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/6/13.
 */
@Service
public class SellerGetMoneyService extends BaseService<SellerGetMoneyRecord, Long> {

    @Resource(name="adminDS")
    private MongoDataSource ds;

    @Override
    protected MongoDataSource getMongoDataSource() {
        return ds;
    }

    @Override
    protected Class<SellerGetMoneyRecord> getEntityClass() {
        return SellerGetMoneyRecord.class;
    }

    public List<SellerGetMoneyRecord> getAllSources() {
        return ds.createQuery(getEntityClass()).asList();
    }

    public int getGotMoney(long sellerId) {
        Map<String, Object> param = Maps.newHashMap();
        param.put("sellerId", sellerId);
        param.put("status", SellerConstants.SellerGetMoneyStatus.PASS);
        List<SellerGetMoneyRecord> recordList = list(param);
        return recordList.stream().mapToInt(SellerGetMoneyRecord::getMoney).sum();
    }
}
